import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from "@angular/router";
import {LocalStorage} from "../app.local-storage";
import {Observable} from "rxjs";
import {WfToast} from "../utils/toast.utils";
import {isNull} from "util";
/**
 * Created by albert on 17/5/11.
 */
export class LoginGuard implements CanActivate{

    ls:any;

    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean>|Promise<boolean>|boolean {
        this.ls=new LocalStorage();
        let token=this.ls.getObject('user').token;
        let user=this.ls.getObject('user');
        // console.log(user,typeof (user),user!=null);
        // console.log(token,typeof (token));
        if(user!=null && token!=undefined){
            return true;
        }else{
            new WfToast().msg('请先登录');
            return false;
        }
    }


}
